## ℹ <https://maps.googleapis.com/maps/api/geocode/json?address=CN+Tower,+Toronto&key=xxx>
## ℹ <https://maps.googleapis.com/maps/api/geocode/json?address=Royal+Ontario+Museum,+Toronto&key=xxx>
## ℹ <https://maps.googleapis.com/maps/api/geocode/json?address=Ripley's+Aquarium+of+Canada,+Toronto&key=xxx>
## ℹ <https://maps.googleapis.com/maps/api/geocode/json?address=Distillery+Historic+District,+Toronto&key=xxx>
## ℹ <https://maps.googleapis.com/maps/api/geocode/json?address=Art+Gallery+of+Ontario,+Toronto&key=xxx>
## ℹ <https://maps.googleapis.com/maps/api/geocode/json?address=Casa+Loma,+Toronto&key=xxx>
## ℹ <https://maps.googleapis.com/maps/api/geocode/json?address=Toronto+Islands,+Toronto&key=xxx>
## ℹ <https://maps.googleapis.com/maps/api/geocode/json?address=St.+Lawrence+Market,+Toronto&key=xxx>
## ℹ <https://maps.googleapis.com/maps/api/geocode/json?address=Hockey+Hall+of+Fame,+Toronto&key=xxx>
## ℹ <https://maps.googleapis.com/maps/api/geocode/json?address=Nathan+Phillips+Square,+Toronto&key=xxx>

Base Map of Sept. Avg Price

Adjacency Matrices & Weights

Why we might want distance over contiguity based?

##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## 0.09091 0.14286 0.16667 0.16746 0.20000 0.33333
## Warning: st_centroid assumes attributes are constant over geometries

##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.3333  0.3333  0.3333  0.3333  0.3333  0.3333

##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.1667  0.1667  0.1667  0.1667  0.1667  0.1667
## Warning in knn2nb(knearneigh(coords, k = 1)): neighbour object has 41
## sub-graphs

##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## 0.06250 0.08333 0.10000 0.14799 0.16667 1.00000

Global Moran’s I

This will give a general statistic for the entire study area. We pick fixed distance with row standardization.

##   weight.matrix   moran.I  expectation    variance      p.value
## 1         Queen 0.2138924 -0.007194245 0.002386915 3.015996e-06
## 2          kNN3 0.1874309 -0.007194245 0.004072117 1.144503e-03
## 3          kNN6 0.1421564 -0.007194245 0.002044641 4.784123e-04
## 4           IDW 0.2170340 -0.007194245 0.002980003 1.999467e-05
##        idw.weights   moran.I  expectation    variance      p.value
## 1 Row Standardized 0.2170340 -0.007194245 0.002980003 1.999467e-05
## 2           Binary 0.1433354 -0.007194245 0.001945729 3.217730e-04

If you’re analyzing Airbnb data in Toronto:

MCMC + Permutation

Similar p-value + significant.

## 
##  Monte-Carlo simulation of Moran I
## 
## data:  nbhd$avg_sept_price 
## weights: dist1.wts  
## number of simulations + 1: 10000 
## 
## statistic = 0.21703, observed rank = 9984, p-value = 0.0016
## alternative hypothesis: greater

Local Moran’s I

## 
##   Low-Low  High-Low  Low-High High-High 
##        51        15        30        44

Local Getis’ Ord

Model Fitting

Linear

## 
## Call:
## lm(formula = avg_sept_price ~ n_sept_listings + n_listings_near_subway + 
##     median_income, data = nbhd)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -112.41  -22.36  -10.27   14.23  389.68 
## 
## Coefficients:
##                          Estimate Std. Error t value Pr(>|t|)    
## (Intercept)            40.9350720 17.5811875   2.328   0.0214 *  
## n_sept_listings        -0.1557997  0.1231602  -1.265   0.2080    
## n_listings_near_subway  0.1930344  0.1210305   1.595   0.1131    
## median_income           0.0007068  0.0001333   5.304 4.48e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 52.25 on 136 degrees of freedom
## Multiple R-squared:  0.2553, Adjusted R-squared:  0.2389 
## F-statistic: 15.54 on 3 and 136 DF,  p-value: 9.528e-09
## 
##  Moran I test under randomisation
## 
## data:  nbhd$lm_resid  
## weights: dist1.wts    
## 
## Moran I statistic standard deviate = 2.0751, p-value = 0.01899
## alternative hypothesis: greater
## sample estimates:
## Moran I statistic       Expectation          Variance 
##       0.095187757      -0.007194245       0.002434230

SAR Spatial Error

## 
## Call: 
## spautolm(formula = avg_sept_price ~ n_sept_listings + n_listings_near_subway + 
##     median_income, data = nbhd, listw = dist1.wts)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -100.8202  -22.3484   -9.3946   12.9395  388.1777 
## 
## Coefficients: 
##                           Estimate  Std. Error z value  Pr(>|z|)
## (Intercept)            42.62153524 18.28459493  2.3310   0.01975
## n_sept_listings        -0.16192243  0.12678158 -1.2772   0.20154
## n_listings_near_subway  0.19576441  0.12529522  1.5624   0.11819
## median_income           0.00069719  0.00013861  5.0299 4.908e-07
## 
## Lambda: 0.18677 LR test value: 2.5338 p-value: 0.11143 
## Numerical Hessian standard error of lambda: 0.11512 
## 
## Log likelihood: -749.1896 
## ML residual variance (sigma squared): 2585.6, (sigma: 50.848)
## Number of observations: 140 
## Number of parameters estimated: 6 
## AIC: 1510.4
## 
##  Moran I test under randomisation
## 
## data:  nbhd$sar_err_resid  
## weights: dist1.wts    
## 
## Moran I statistic standard deviate = 0.10918, p-value = 0.4565
## alternative hypothesis: greater
## sample estimates:
## Moran I statistic       Expectation          Variance 
##      -0.001834502      -0.007194245       0.002409946

SAR Spatial Lag

## 
## Call:
## lagsarlm(formula = avg_sept_price ~ n_sept_listings + n_listings_near_subway + 
##     median_income, data = nbhd, listw = dist1.wts)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -96.5218 -22.2672  -9.6825  11.4059 390.3965 
## 
## Type: lag 
## Coefficients: (asymptotic standard errors) 
##                           Estimate  Std. Error z value  Pr(>|z|)
## (Intercept)            24.21027309 19.80738113  1.2223    0.2216
## n_sept_listings        -0.11753964  0.12208107 -0.9628    0.3356
## n_listings_near_subway  0.15180256  0.12021029  1.2628    0.2067
## median_income           0.00064917  0.00013454  4.8252 1.398e-06
## 
## Rho: 0.18443, LR test value: 2.8662, p-value: 0.090456
## Asymptotic standard error: 0.11103
##     z-value: 1.6611, p-value: 0.09669
## Wald statistic: 2.7593, p-value: 0.09669
## 
## Log likelihood: -749.0234 for lag model
## ML residual variance (sigma squared): 2579.9, (sigma: 50.793)
## Number of observations: 140 
## Number of parameters estimated: 6 
## AIC: 1510, (AIC for lm: 1510.9)
## LM test for residual autocorrelation
## test value: 0.0013941, p-value: 0.97022
## 
##  Moran I test under randomisation
## 
## data:  nbhd$sar_lag_resid  
## weights: dist1.wts    
## 
## Moran I statistic standard deviate = 0.13041, p-value = 0.4481
## alternative hypothesis: greater
## sample estimates:
## Moran I statistic       Expectation          Variance 
##     -0.0008106219     -0.0071942446      0.0023961264

SAR Spatial Lag + Error

## 
## Call:
## sacsarlm(formula = avg_sept_price ~ n_sept_listings + n_listings_near_subway, 
##     data = nbhd, listw = dist1.wts)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -71.792 -28.269 -10.020  14.003 367.884 
## 
## Type: sac 
## Coefficients: (asymptotic standard errors) 
##                        Estimate Std. Error z value Pr(>|z|)
## (Intercept)            77.73725   38.20353  2.0348  0.04187
## n_sept_listings        -0.23849    0.13776 -1.7311  0.08343
## n_listings_near_subway  0.26691    0.13809  1.9329  0.05325
## 
## Rho: 0.39544
## Asymptotic standard error: 0.29206
##     z-value: 1.354, p-value: 0.17574
## Lambda: -0.12722
## Asymptotic standard error: 0.37831
##     z-value: -0.3363, p-value: 0.73665
## 
## LR test value: 7.2499, p-value: 0.02665
## 
## Log likelihood: -759.9923 for sac model
## ML residual variance (sigma squared): 2926.8, (sigma: 54.1)
## Number of observations: 140 
## Number of parameters estimated: 6 
## AIC: 1532, (AIC for lm: 1535.2)
## 
##  Moran I test under randomisation
## 
## data:  nbhd$sar_lag_err_resid  
## weights: dist1.wts    
## 
## Moran I statistic standard deviate = 0.13808, p-value = 0.4451
## alternative hypothesis: greater
## sample estimates:
## Moran I statistic       Expectation          Variance 
##      -0.000303365      -0.007194245       0.002490436

CAR

## Warning in spautolm(avg_sept_price ~ n_sept_listings + n_listings_near_subway,
## : Non-symmetric spatial weights in CAR model
## 
## Call: 
## spautolm(formula = avg_sept_price ~ n_sept_listings + n_listings_near_subway, 
##     data = nbhd, listw = dist1.wts, family = "CAR")
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -76.162 -29.414  -8.703  14.566 363.323 
## 
## Coefficients: 
##                         Estimate Std. Error z value  Pr(>|z|)
## (Intercept)            132.58890    7.94417 16.6901 < 2.2e-16
## n_sept_listings         -0.39248    0.13800 -2.8441  0.004453
## n_listings_near_subway   0.41018    0.13676  2.9993  0.002706
## 
## Lambda: 0.5133 LR test value: 6.0853 p-value: 0.013631 
## Numerical Hessian standard error of lambda: 0.19776 
## 
## Log likelihood: -760.5746 
## ML residual variance (sigma squared): 2971.4, (sigma: 54.511)
## Number of observations: 140 
## Number of parameters estimated: 5 
## AIC: 1531.1
## 
##  Moran I test under randomisation
## 
## data:  nbhd$car_resid  
## weights: dist1.wts    
## 
## Moran I statistic standard deviate = -2.0092, p-value = 0.9777
## alternative hypothesis: greater
## sample estimates:
## Moran I statistic       Expectation          Variance 
##      -0.108456646      -0.007194245       0.002540168